<?php
class Solphr_SQLIndexer {
	private $pdo;
	private $SQL;
	private $add;
	
	public function __construct($dsn, $URL) {
		if(!class_exists('pdo')) {
			throw new Solphr_Exception('PDO is required for this utility.');
		} else {
			$this->pdo = new pdo($dsn);
		}
		
		$this->add = new Solphr_AddUpdate($URL);
		
		ini_set('memory_limit', '256M');
		set_time_limit(0);
	}
	
	public function setSQL($SQL) {
		$this->SQL = $SQL;
	}
	
	public function execute($params = null) {
		$stmt = $this->pdo->prepare($this->SQL);
		$stmt->execute($params);
		
		$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
		
		foreach($records as $record) {
			$record = new Solphr_Record($record);
			$this->add->addRecord($record);
		}
		
		$this->add->submitRecords();
		$this->add->commit();
	}
}